/* 
 * File:   synchrone.cpp
 * Author: cyril
 * 
 * Created on 10 décembre 2012, 09:33
 */
#include<iostream>
#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv []) {
    int rang;
    char message1 [30];
    char message2 [30];
    MPI_Status status;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rang);
    switch (rang) {
        case 0: while (1) {
                MPI_Send(&message1, 1, MPI_CHAR, 1, 99, MPI_COMM_WORLD);
                printf("0 envoie a 1\n");
                MPI_Recv(&message2, 1, MPI_CHAR, MPI_ANY_SOURCE, 98, MPI_COMM_WORLD, &status);
                printf("0 recoit de 1\n");
            }
            break;
        case 1: while (1) {
                MPI_Recv(&message1, 1, MPI_CHAR, MPI_ANY_SOURCE, 99, MPI_COMM_WORLD, &status);
                printf(rang + " recoit de 0\n");
                MPI_Send(&message2, 1, MPI_CHAR, 0, 98, MPI_COMM_WORLD);
                printf(rang + " envoie a 0\n");
            }
        break;
    }
    MPI_Finalize();
}




